import { message } from 'ant-design-vue';
import { defineStore } from 'pinia';

export const useImgEventStore = defineStore('imgEvent', () => {
  const eventList = ref<any[]>([]);
  const getEventList = async () => {
    eventList.value = [];
    await getEvent().then((res: any) => {
      eventList.value = res.data;
    });
    eventList.value.push({ folderName: '无分配文件夹的文件' });
  };
  const updateEventItem = async (id: number, name: string) => {
    await updateEvent(id, name).then(() => {
      message.success('编辑文件夹成功！');
    });
  };
  const deleteEventItem = async (id: number) => {
    await deleteEvent(id).then(() => {
      message.success('删除文件夹成功！');
    });
  };
  const addEventItem = async (name: string) => {
    await createEvent(name).then(() => {
      message.success('创建文件夹成功！');
    });
  };
  const getList = () => {
    const list: any[] = [];
    eventList.value.forEach((item: any) => {
      list.push(item.folderName);
    });
    return list;
  };
  return {
    eventList,
    getEventList,
    updateEventItem,
    deleteEventItem,
    addEventItem,
    getList,
  };
}, {
  persist: true,
});
